using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class forums_controls_administration_ModifyYCode : Controls.DataManagerYCodeControl
{
    public event EventHandler YCodeModified;
    protected override void ItemChanged()
    {
        Refresh();
    }

    public void Refresh()
    {
        if (CurrentYCode != null)
        {
            txtTag.Text = CurrentYCode.Code;
            chkNesting.Checked = CurrentYCode.SupportNestedTags;
            txtArguments.Text = CurrentYCode.TotalArguments.ToString();
            txtTemplate.Text = CurrentYCode.Template;
            YCodeTransforms1.CurrentYCode = CurrentYCode;
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Page.IsValid && CurrentYCode != null)
        {
            CurrentYCode.Code = txtTag.Text;
            CurrentYCode.SupportNestedTags = chkNesting.Checked;
            CurrentYCode.TotalArguments = Convert.ToInt32(txtArguments.Text);
            CurrentYCode.Template = txtTemplate.Text;
            DAL.YCodes.Save(CurrentYCode);

            if (YCodeModified != null)
            {
                YCodeModified(this, new EventArgs());
            }
        }
    }
    protected void lnkAddTransform_Click(object sender, EventArgs e)
    {
        DAL.YCodeTransform myTransform = new DAL.YCodeTransform();
        myTransform.YCode = CurrentYCode;
        myTransform.Pattern = "(.*)";
        myTransform.Replacement = "$1";

        DAL.YCodeTransforms.Add(myTransform);

        YCodeTransforms1.Refresh();
    }
}
